package com.example.springtest1;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonTest {
    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper=new ObjectMapper();
        String json="{\"name\":\"zhangsan\",\"age\":19,\"sex\":\"nan\"}";
        Student student=objectMapper.readValue(json,Student.class);
        System.out.println(student);

        //对象转字符串
        String jsonstr=objectMapper.writeValueAsString(student);
        System.out.println(jsonstr);
    }
}
